from django.db import models
from django.conf import settings
from .class_task_todo import ClassTaskTodo
from .base_model import BaseModel

class Notification(BaseModel):
    """通知模型，用于校长、年级组长、班主任向其领导的用户发送通知"""
    title = models.CharField(max_length=200, verbose_name="通知标题")
    content = models.TextField(verbose_name="通知内容")
    sender = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        related_name='sent_notifications',
        verbose_name="发送者"
    )
    receiver = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        related_name='received_notifications',
        verbose_name="接收者"
    )
    is_read = models.BooleanField(default=False, verbose_name="是否已读")
    task = models.ForeignKey(
        ClassTaskTodo,
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name='notifications',
        verbose_name="关联待办事务"
    )

    class Meta:
        verbose_name = "通知"
        verbose_name_plural = "通知"
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.sender.username} 发送给 {self.receiver.username}: {self.title}"